home *** CD-ROM | disk | FTP | other *** search
/ By Popular Request 2.0 / By Popular Request 2.0 (Arsenal Computer).ISO / amiga_1 / atcpsd40.lha / AmiTCP-4.0-gcc / netinclude / net / if.h < prev    next >
C/C++ Source or Header  |  1995-06-04  |  8KB  |  236 lines

  1. /*
  2.  * Copyright (c) 1982, 1986 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that the above copyright notice and this paragraph are
  7.  * duplicated in all such forms and that any documentation,
  8.  * advertising materials, and other materials related to such
  9.  * distribution and use acknowledge that the software was developed
  10.  * by the University of California, Berkeley.  The name of the
  11.  * University may not be used to endorse or promote products derived
  12.  * from this software without specific prior written permission.
  13.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  14.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  15.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  16.  *
  17.  *    @(#)if.h        7.3 (Berkeley) 6/27/88
  18.  */
  19.  
  20. /*
  21.  * Structures defining a network interface, providing a packet
  22.  * transport mechanism (ala level 0 of the PUP protocols).
  23.  *
  24.  * Each interface accepts output datagrams of a specified maximum
  25.  * length, and provides higher level routines with input datagrams
  26.  * received from its medium.
  27.  *
  28.  * Output occurs when the routine if_output is called, with three parameters:
  29.  *    (*ifp->if_output)(ifp, m, dst)
  30.  * Here m is the mbuf chain to be sent and dst is the destination address.
  31.  * The output routine encapsulates the supplied datagram if necessary,
  32.  * and then transmits it on its medium.
  33.  *
  34.  * On input, each interface unwraps the data received by it, and either
  35.  * places it on the input queue of a internetwork datagram routine
  36.  * and posts the associated software interrupt, or passes the datagram to a raw
  37.  * packet input routine.
  38.  *
  39.  * Routines exist for locating interfaces by their addresses
  40.  * or for locating a interface on a certain network, as well as more general
  41.  * routing and gateway routines maintaining information used to locate
  42.  * interfaces.    These routines live in the files if.c and route.c
  43.  */
  44.  
  45. /*
  46.  * Structure defining a queue for a network interface.
  47.  *
  48.  * (Would like to call this struct ``if'', but C isn't PL/1.)
  49.  */
  50. struct ifnet {
  51.     char    *if_name;        /* name, e.g. ``en'' or ``lo'' */
  52.     short    if_unit;        /* sub-unit for lower level driver */
  53.     short    if_mtu;         /* maximum transmission unit */
  54.     short    if_flags;        /* up/down, broadcast, etc. */
  55.     short    if_timer;        /* time 'til if_watchdog called */
  56.     int    if_metric;        /* routing metric (external only) */
  57.     struct    ifaddr *if_addrlist;    /* linked list of addresses per if */
  58.     struct    ifqueue {
  59.         struct    mbuf *ifq_head;
  60.         struct    mbuf *ifq_tail;
  61.         int    ifq_len;
  62.         int    ifq_maxlen;
  63.         int    ifq_drops;
  64.     } if_snd;            /* output queue */
  65. /* procedure handles */
  66.     int    (*if_init)();           /* init routine */
  67.     int    (*if_output)();         /* output routine */
  68.     int    (*if_ioctl)();          /* ioctl routine */
  69.     int    (*if_reset)();          /* bus reset routine */
  70.     int    (*if_watchdog)();       /* timer routine */
  71. /* generic interface statistics */
  72.     int    if_ipackets;        /* packets received on interface */
  73.     int    if_ierrors;        /* input errors on interface */
  74.     int    if_opackets;        /* packets sent on interface */
  75.     int    if_oerrors;        /* output errors on interface */
  76.     int    if_collisions;        /* collisions on csma interfaces */
  77. /* end statistics */
  78.     struct    ifnet *if_next;
  79. };
  80.  
  81. #define IFF_UP        0x1        /* interface is up */
  82. #define IFF_BROADCAST    0x2        /* broadcast address valid */
  83. #define IFF_DEBUG    0x4        /* turn on debugging */
  84. #define IFF_LOOPBACK    0x8        /* is a loopback net */
  85. #define IFF_POINTOPOINT 0x10        /* interface is point-to-point link */
  86. #define IFF_NOTRAILERS    0x20        /* avoid use of trailers */
  87. #define IFF_RUNNING    0x40        /* resources allocated */
  88. #define IFF_NOARP    0x80        /* no address resolution protocol */
  89. /* next two not supported now, but reserved: */
  90. #define IFF_PROMISC    0x100        /* receive all packets */
  91. #define IFF_ALLMULTI    0x200        /* receive all multicast packets */
  92. /* flags set internally only: */
  93. #define IFF_CANTCHANGE    (IFF_BROADCAST | IFF_POINTOPOINT | IFF_RUNNING)
  94. #define IFF_SIMPLEX    0x800        /* can't hear own transmissions */
  95.  
  96. /*
  97.  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
  98.  * input routines have queues of messages stored on ifqueue structures
  99.  * (defined above).  Entries are added to and deleted from these structures
  100.  * by these macros, which should be called with ipl raised to splimp().
  101.  */
  102. #define IF_QFULL(ifq)           ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
  103. #define IF_DROP(ifq)            ((ifq)->ifq_drops++)
  104. #define IF_ENQUEUE(ifq, m) { \
  105.     (m)->m_act = 0; \
  106.     if ((ifq)->ifq_tail == 0) \
  107.         (ifq)->ifq_head = m; \
  108.     else \
  109.         (ifq)->ifq_tail->m_act = m; \
  110.     (ifq)->ifq_tail = m; \
  111.     (ifq)->ifq_len++; \
  112. }
  113. #define IF_PREPEND(ifq, m) { \
  114.     (m)->m_act = (ifq)->ifq_head; \
  115.     if ((ifq)->ifq_tail == 0) \
  116.         (ifq)->ifq_tail = (m); \
  117.     (ifq)->ifq_head = (m); \
  118.     (ifq)->ifq_len++; \
  119. }
  120. /*
  121.  * Packets destined for level-1 protocol input routines
  122.  * have a pointer to the receiving interface prepended to the data.
  123.  * IF_DEQUEUEIF extracts and returns this pointer when dequeueing the packet.
  124.  * IF_ADJ should be used otherwise to adjust for its presence.
  125.  */
  126. #define IF_ADJ(m) { \
  127.     (m)->m_off += sizeof(struct ifnet *); \
  128.     (m)->m_len -= sizeof(struct ifnet *); \
  129.     if ((m)->m_len == 0) { \
  130.         struct mbuf *n; \
  131.         MFREE((m), n); \
  132.         (m) = n; \
  133.     } \
  134. }
  135. #define IF_DEQUEUEIF(ifq, m, ifp) { \
  136.     (m) = (ifq)->ifq_head; \
  137.     if (m) { \
  138.         if (((ifq)->ifq_head = (m)->m_act) == 0) \
  139.             (ifq)->ifq_tail = 0; \
  140.         (m)->m_act = 0; \
  141.         (ifq)->ifq_len--; \
  142.         (ifp) = *(mtod((m), struct ifnet **)); \
  143.         IF_ADJ(m); \
  144.     } \
  145. }
  146. #define IF_DEQUEUE(ifq, m) { \
  147.     (m) = (ifq)->ifq_head; \
  148.     if (m) { \
  149.         if (((ifq)->ifq_head = (m)->m_act) == 0) \
  150.             (ifq)->ifq_tail = 0; \
  151.         (m)->m_act = 0; \
  152.         (ifq)->ifq_len--; \
  153.     } \
  154. }
  155.  
  156. #define IFQ_MAXLEN    50
  157. #define IFNET_SLOWHZ    1        /* granularity is 1 second */
  158.  
  159. /*
  160.  * The ifaddr structure contains information about one address
  161.  * of an interface.  They are maintained by the different address families,
  162.  * are allocated and attached when an address is set, and are linked
  163.  * together so all addresses for an interface can be located.
  164.  */
  165. struct ifaddr {
  166.     struct    sockaddr ifa_addr;    /* address of interface */
  167.     union {
  168.         struct    sockaddr ifu_broadaddr;
  169.         struct    sockaddr ifu_dstaddr;
  170.     } ifa_ifu;
  171. #define ifa_broadaddr    ifa_ifu.ifu_broadaddr    /* broadcast address */
  172. #define ifa_dstaddr    ifa_ifu.ifu_dstaddr    /* other end of p-to-p link */
  173.     struct    ifnet *ifa_ifp;     /* back-pointer to interface */
  174.     struct    ifaddr *ifa_next;    /* next address for interface */
  175. };
  176.  
  177. /*
  178.  * Interface request structure used for socket
  179.  * ioctl's.  All interface ioctl's must have parameter
  180.  * definitions which begin with ifr_name.  The
  181.  * remainder may be interface specific.
  182.  */
  183. struct    ifreq {
  184. #define IFNAMSIZ    16
  185.     char    ifr_name[IFNAMSIZ];        /* if name, e.g. "en0" */
  186.     union {
  187.         struct    sockaddr ifru_addr;
  188.         struct    sockaddr ifru_dstaddr;
  189.         struct    sockaddr ifru_broadaddr;
  190.         short    ifru_flags;
  191.         int    ifru_metric;
  192.         caddr_t ifru_data;
  193.     } ifr_ifru;
  194. #define ifr_addr    ifr_ifru.ifru_addr    /* address */
  195. #define ifr_dstaddr    ifr_ifru.ifru_dstaddr    /* other end of p-to-p link */
  196. #define ifr_broadaddr    ifr_ifru.ifru_broadaddr /* broadcast address */
  197. #define ifr_flags    ifr_ifru.ifru_flags    /* flags */
  198. #define ifr_metric    ifr_ifru.ifru_metric    /* metric */
  199. #define ifr_data    ifr_ifru.ifru_data    /* for use by interface */
  200. };
  201.  
  202. #ifdef __AMITCP__
  203. struct ifaliasreq {
  204.     char    ifra_name[IFNAMSIZ];        /* if name, e.g. "en0" */
  205.     struct    sockaddr ifra_addr;
  206.     struct    sockaddr ifra_broadaddr;
  207.     struct    sockaddr ifra_mask;
  208. };
  209. #endif
  210.  
  211. /*
  212.  * Structure used in SIOCGIFCONF request.
  213.  * Used to retrieve interface configuration
  214.  * for machine (useful for programs which
  215.  * must know all networks accessible).
  216.  */
  217. struct    ifconf {
  218.     int    ifc_len;        /* size of associated buffer */
  219.     union {
  220.         caddr_t ifcu_buf;
  221.         struct    ifreq *ifcu_req;
  222.     } ifc_ifcu;
  223. #define ifc_buf ifc_ifcu.ifcu_buf    /* buffer address */
  224. #define ifc_req ifc_ifcu.ifcu_req    /* array of structures returned */
  225. };
  226.  
  227. #ifdef KERNEL
  228. #include <net/if_arp.h>
  229. struct    ifqueue rawintrq;        /* raw packet input queue */
  230. struct    ifnet *ifnet;
  231. struct    ifaddr *ifa_ifwithaddr(), *ifa_ifwithnet();
  232. struct    ifaddr *ifa_ifwithdstaddr();
  233. #else KERNEL
  234. #include <net/if_arp.h>
  235. #endif KERNEL
  236.